package com.hoshiicloud.mallshop.service.impl.fileupload;

import com.hoshiicloud.common.query.UploadFileResponse;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.mallshop.feign.ShopFileUploadService;
import com.hoshiicloud.mallshop.service.fileupload.StoreFileUploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * 店铺文件上传
 * @author linjx on 2019/9/23
 */
@Slf4j
@Service
public class StoreFileUploadServiceImpl implements StoreFileUploadService {

    @Autowired
    private ShopFileUploadService fileUpload;

    /**
     * 店铺文件上传
     */
    @Override
    public UploadFileResponse uploadFile(MultipartFile file, String folderName) {

        log.info("文件名:"+file.getOriginalFilename());
        String bucketName = "obs-7d37";
        String objectKey = file.getOriginalFilename();
        String fileName = file.getOriginalFilename();
        String folder = folderName;
        Boolean privateOwned = false;
        Response<UploadFileResponse> response = fileUpload.fileUpload(bucketName, objectKey, fileName, folder, privateOwned, file);
        log.info(response.toString());
        return response.getData();
    }
}
